import { Table, Tag, Space } from 'antd';
import request from '@/http';
import { useState } from 'react';
import * as React from 'react';

const columns = [
  {
    title: '小组名称',
    dataIndex: 'teamName',
    key: 'teamName',
  },
  {
    title: '小组成员',
    dataIndex: 'stuName',
    key: 'stuName',
  },
  {
    title: '项目角色',
    dataIndex: 'position',
    key: 'position',
  },
  {
    title: '组长',
    dataIndex: 'isTeamLeader',
    key: 'isTeamLeader',
  },
  {
    title: '标准学时',
    dataIndex: 'standard',
    key: 'standard',
  },
  {
    title: '大课学时',
    dataIndex: 'main',
    key: 'main',
  },
  {
    title: '自习学时',
    dataIndex: 'self',
    key: 'self',
  },
  {
    title: '联系电话',
    dataIndex: 'mobileNo',
    key: 'mobileNo',
  },
];

export default () => {
  const [dataSource, setDataSource] = useState([]);
  const [loading, setLoading] = useState(true);
  const loadDataSource = async () => {
    const result: any = await request.get('/api/student/queryTeamClassHour');
    if (result.success) {
      let sum = 0;
      const data = result.data.map((student: any) => ({
        key: `clazz_${sum++}`,
        main: student.main,
        mobileNo: student.mobileNo,
        position: student.position,
        self: student.self,
        standard: student.standard,
        stuName: student.stuName,
        teamName: student.teamName,
        isTeamLeader: student.isTeamLeader == '1' ? '√' : '',
      }));
      setLoading(false);
      setDataSource(data);
    }
  };
  React.useEffect(() => {
    loadDataSource().finally();
  }, []);
  return (
    <Table
      bordered
      columns={columns}
      dataSource={dataSource}
      loading={loading}
      pagination={false}
    />
  );
};
